package com.sailing.core.demo.doutresolving;

public class NumberIsOdd {
	/**
	 * 只能支持正数，负奇数取余为-1
	 * @param val
	 * @return
	 */
	public static boolean isOdd(int val){
		return val%2==1;
	}
	/**
	 * 正确的实现
	 * @param val
	 * @return
	 */
	public static boolean isOdd1(int val){
		return val % 2 != 0;
	}
	/**
	 * 性能最优
	 * @param val
	 * @return
	 */
	public static boolean isOdd2(int val){
		return (val & 1) != 0;
	}
	public static boolean isOdd5(int val){
		return (val | 5) == 5;
	}
	public static void main(String[] args) {
		System.out.println(NumberIsOdd.isOdd(-1));
		System.out.println(NumberIsOdd.isOdd(0));
		System.out.println(NumberIsOdd.isOdd(1));
		
		
		System.out.println(NumberIsOdd.isOdd1(-1));
		System.out.println(NumberIsOdd.isOdd2(-1));
		System.out.println(NumberIsOdd.isOdd2(5));
		System.out.println(isOdd5(5));
		System.out.println(1113&5);
	}
}
